package com.activiti.spring.controller;

import java.util.HashMap;
import java.util.Map;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SequenceFlowController {
	@Autowired
	private RepositoryService repositoryService;
	@Autowired
	private RuntimeService runtimeService;
	@Autowired
	private TaskService taskService;
	
	@GetMapping("getDeploySequenceFlow")
	@ResponseBody
	public Deployment getDeploySequenceFlow() {
		Deployment deploy = repositoryService.createDeployment().name("审批流程")
				.addClasspathResource("diagrams/SequenceFlow.bpmn").deploy();
		System.out.println("部署id:" + deploy.getId());
		System.out.println("部署名称：" + deploy.getName());
		return deploy;
	}
	
	@GetMapping("completeSequenceFlow")
	@ResponseBody
	public String completeSequenceFlow(Model model,@RequestParam("taskId") String taskId){
		Map<String,Object> map=new HashMap<>();
		map.put("messge", "重要");//连线表达式
		taskService.complete(taskId,map);
		return taskId;
	}

}
